<template>
  <div>
    <n-drawer v-model:show="showModal" :width="dialogWidth">
      <n-drawer-content title="竞拍记录详情" closable>
        <n-spin :show="loading" description="请稍候...">
          <n-descriptions label-placement="left" class="py-2" :column="1">
            <n-descriptions-item label="竞拍活动">
              <n-tag :type="dict.getType('auctionOption', formValue.auctionId)" size="small" class="min-left-space">
                {{ dict.getLabel('auctionOption', formValue.auctionId) }}
              </n-tag>
            </n-descriptions-item>
            <n-descriptions-item label="产品">
              <n-tag :type="dict.getType('productOption', formValue.productId)" size="small" class="min-left-space">
                {{ dict.getLabel('productOption', formValue.productId) }}
              </n-tag>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                最终成交价格
              </template>
              {{ formValue.finalPrice }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                参与人数
              </template>
              {{ formValue.numberOfParticipants }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                出价日志
              </template>
              <n-data-table :columns="columns" :data="formValue.bidLog" />
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                日期
              </template>
              <n-time :time="formValue.date" format="yyyy-MM-dd" />
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                开始时间
              </template>
              {{ formValue.startTime }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                结束时间
              </template>
              {{ formValue.endTime }}
            </n-descriptions-item>
          </n-descriptions>
        </n-spin>
      </n-drawer-content>
    </n-drawer>
  </div>
</template>

<script lang="ts" setup>
  import { computed, ref } from 'vue';
  import { useMessage } from 'naive-ui';
  import { View } from '@/api/auctionLog';
  import { State, newState } from './model';
  import { adaModalWidth } from '@/utils/hotgo';
  import { getFileExt } from '@/utils/urlUtils';
  import { useDictStore } from '@/store/modules/dict';
  import { renderPopoverMemberSumma } from '@/utils';

  const message = useMessage();
  const dict = useDictStore();
  const loading = ref(false);
  const showModal = ref(false);
  const formValue = ref(newState(null));
  const dialogWidth = computed(() => {
    return adaModalWidth(580);
  });
  const columns = ref([
    {
      title: '出价人',
      key: 'userId',
      render(row) {
        return renderPopoverMemberSumma({id: row.userId, realName: row.adminMemberRealName, username: row.adminMemberUsername, avatar:row.adminMemberAvatar})
      },
    },
    {
      title: '出价价格',
      key: 'bidAmount',
    },
    {
      title: '出价时间',
      key: 'bidTime',
    },
  ]);
  const fileAvatarCSS = computed(() => {
    return {
      '--n-merged-size': `var(--n-avatar-size-override, 80px)`,
      '--n-font-size': `18px`,
    };
  });

  // 下载
  function download(url: string) {
    window.open(url);
  }

  // 打开模态框
  function openModal(state: State) {
    showModal.value = true;
    loading.value = true;
    View({ id: state.id })
      .then((res) => {
        formValue.value = res;
      })
      .finally(() => {
        loading.value = false;
      });
  }

  defineExpose({
    openModal,
  });
</script>

<style lang="less" scoped></style>
